﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using Wys.ClosePopup;

namespace Wys.ClosePopup
{
    public partial class OptionCloseForm : Form
    {
        ClosePopupConfig _cs = null;
        public OptionCloseForm(ClosePopupConfig cs)
        {
            _cs = cs;
            InitializeComponent();
        }

        private void btn确定_Click(object sender, EventArgs e)
        {
            if (this.txtTitle.Text.Trim() == "")
            {
                MessageBox.Show("标题不能为空", "选项");
                return;
            }

            if (nmInterval.Value < 100)
            {
                MessageBox.Show("间隔不能小于100毫秒", "选项");
                return;
            }

            //String[] strFind = this.txtFindText.Lines;
            //if (strFind.Length == 0)
            //{
            //    MessageBox.Show("查找字符串不能为空", "选项");
            //    return;
            //}

            bool noData = true ;
            //for (int i = 0; i < strFind.Length; i++)
            //{
            //    if (strFind[i].Trim() != "")
            //    {
            //        noData = false;
            //        break;
            //    }
            //}
            if (noData)
            {
                MessageBox.Show("查找字符串不能为空", "选项");
                return;
            }

            Configuration con = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            con.AppSettings.Settings["AppTitle"].Value = this.txtTitle.Text.TrimEnd() ;
            con.AppSettings.Settings["TimeSpan"].Value =nmInterval.Value.ToString();
            String str = "";
            //for (int i = 0; i < txtFindText.Lines.Length; i++)
            //{
            //    if (txtFindText.Lines[i].Trim() != "")
            //    {
            //        str += txtFindText.Lines[i].Trim()+",";
            //    }
            //}
            if (str.EndsWith(","))
            {
                str = str.Substring(0, str.Length - 1);
            }
            con.AppSettings.Settings["FindString"].Value = str;
            con.Save();
            MessageBox.Show("保存成功，请重新打开", "选项");
            this.Close();
        }

        private void OptionCloseForm_Load(object sender, EventArgs e)
        {
            //this.txtTitle.Text = ConfigurationManager.AppSettings["AppTitle"];
            //this.nmInterval.Value = int.Parse(ConfigurationManager.AppSettings["TimeSpan"]);
            //String[] strContent = ConfigurationManager.AppSettings["FindString"].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            //System.Text.StringBuilder sb = new StringBuilder();
            //for (int i = 0; i < strContent.Length; i++)
            //{
            //    sb.AppendLine(strContent[i]);
            //}
            //this.txtFindText.Text = sb.ToString();
        }

        private void btn添加_Click(object sender, EventArgs e)
        {

        }

        private void btn修正_Click(object sender, EventArgs e)
        {

        }

        private void btn删除_Click(object sender, EventArgs e)
        {

        }
    }
}
